package com.example.auth.handler;

import com.example.auth.constants.CommonConstants;
import com.example.auth.exception.NoAccessException;
import com.example.auth.exception.ParamInvalidException;
import com.example.auth.exception.UserInvalidException;
import com.example.auth.model.BaseResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileNotFoundException;

/**
 * Created by wangtao on 2018/3/3.
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(UserInvalidException.class)
    public BaseResponse userInvalidExceptionHandler(Exception ex) {
        return new BaseResponse(CommonConstants.EX_USER_INVALID_CODE,ex.getMessage());
    }
    @ExceptionHandler(ParamInvalidException.class)
    public BaseResponse paramInvalidExceptionHandler(Exception ex) {
        return new BaseResponse(CommonConstants.EX_PARAM_ILLEGAL_CODE,ex.getMessage());
    }
    @ExceptionHandler(NoAccessException.class)
    public BaseResponse noAccessExceptionHandler(Exception ex) {
        return new BaseResponse(CommonConstants.EX_NO_SERVICE_ACCESS_CODE,ex.getMessage());
    }
    @ExceptionHandler(FileNotFoundException.class)
    public BaseResponse fileNotFoundExceptionHandler(Exception ex) {
        return new BaseResponse(CommonConstants.EX_NOT_FOUND_CODE,ex.getMessage());
    }
}
